package org.ycx.upms.dao.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.ycx.upms.dao.auto.SecUserMapper;
import org.ycx.upms.dao.model.SecUser;

import java.util.List;

/**
 * SecUser 自定义Mapper
 * Created by yang on 2017-07-19 15:08:27.
 */
public interface ISecUserMapper extends SecUserMapper {
    @Select("select su.* from sec_user su,sec_user_role sur where sur.USER_ID = su.UID and sur.ROLE_ID=#{id}")
    @Results({
            @Result(column = "UID", property = "uid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "LOGIN_NAME", property = "loginName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PASSWD", property = "passwd", jdbcType = JdbcType.VARCHAR),
            @Result(column = "NICK_NAME", property = "nickName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "GENDER", property = "gender", jdbcType = JdbcType.VARCHAR),
            @Result(column = "MOBILE", property = "mobile", jdbcType = JdbcType.VARCHAR),
            @Result(column = "EMAIL", property = "email", jdbcType = JdbcType.VARCHAR),
            @Result(column = "AVATER", property = "avater", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PWD_END_DATE", property = "pwdEndDate", jdbcType = JdbcType.DATE),
            @Result(column = "USE_STATE", property = "useState", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DEL_STATE", property = "delState", jdbcType = JdbcType.VARCHAR),
            @Result(column = "CREATE_TS", property = "createTs", jdbcType = JdbcType.DATE),
            @Result(column = "CREATE_UID", property = "createUid", jdbcType = JdbcType.INTEGER),
            @Result(column = "UPDATE_TS", property = "updateTs", jdbcType = JdbcType.DATE),
            @Result(column = "UPDATE_UID", property = "updateUid", jdbcType = JdbcType.INTEGER)
    })
    List<SecUser> selectUserByRoleId(@Param("id") Integer rid);

    @Select("select count(1) from sec_user su,sec_user_role sur where sur.USER_ID = su.UID and sur.ROLE_ID=#{id}")
    long countUserByRoleId(Integer rid);

    @Select("select ROLE_ID from sec_user_role where USER_ID=#{id}")
    List<Integer> selectRidByUid(@Param("id") Integer uid);

    @Select("select su.* from sec_user su,sec_group_user sur where sur.UID = su.UID and sur.GROUP_ID=#{id}")
    @Results({
            @Result(column = "UID", property = "uid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "LOGIN_NAME", property = "loginName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PASSWD", property = "passwd", jdbcType = JdbcType.VARCHAR),
            @Result(column = "NICK_NAME", property = "nickName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "GENDER", property = "gender", jdbcType = JdbcType.VARCHAR),
            @Result(column = "MOBILE", property = "mobile", jdbcType = JdbcType.VARCHAR),
            @Result(column = "EMAIL", property = "email", jdbcType = JdbcType.VARCHAR),
            @Result(column = "AVATER", property = "avater", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PWD_END_DATE", property = "pwdEndDate", jdbcType = JdbcType.DATE),
            @Result(column = "USE_STATE", property = "useState", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DEL_STATE", property = "delState", jdbcType = JdbcType.VARCHAR),
            @Result(column = "CREATE_TS", property = "createTs", jdbcType = JdbcType.DATE),
            @Result(column = "CREATE_UID", property = "createUid", jdbcType = JdbcType.INTEGER),
            @Result(column = "UPDATE_TS", property = "updateTs", jdbcType = JdbcType.DATE),
            @Result(column = "UPDATE_UID", property = "updateUid", jdbcType = JdbcType.INTEGER)
    })
    List<SecUser> selectUserByGroup(@Param("id") Integer gid);

    @Select("select count(1) from sec_user su,sec_group_user sur where sur.UID = su.UID and sur.GROUP_ID=#{id}")
    long countUserByGroup(@Param("id") Integer gid);


    @Select("select su.* from sec_user su,sec_attachment_user sur where sur.USER_ID = su.UID and sur.ATTR_ID=#{id}")
    @Results({
            @Result(column = "UID", property = "uid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "LOGIN_NAME", property = "loginName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PASSWD", property = "passwd", jdbcType = JdbcType.VARCHAR),
            @Result(column = "NICK_NAME", property = "nickName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "GENDER", property = "gender", jdbcType = JdbcType.VARCHAR),
            @Result(column = "MOBILE", property = "mobile", jdbcType = JdbcType.VARCHAR),
            @Result(column = "EMAIL", property = "email", jdbcType = JdbcType.VARCHAR),
            @Result(column = "AVATER", property = "avater", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PWD_END_DATE", property = "pwdEndDate", jdbcType = JdbcType.DATE),
            @Result(column = "USE_STATE", property = "useState", jdbcType = JdbcType.VARCHAR),
            @Result(column = "DEL_STATE", property = "delState", jdbcType = JdbcType.VARCHAR),
            @Result(column = "CREATE_TS", property = "createTs", jdbcType = JdbcType.DATE),
            @Result(column = "CREATE_UID", property = "createUid", jdbcType = JdbcType.INTEGER),
            @Result(column = "UPDATE_TS", property = "updateTs", jdbcType = JdbcType.DATE),
            @Result(column = "UPDATE_UID", property = "updateUid", jdbcType = JdbcType.INTEGER)
    })
    List<SecUser> selectUserByAttach(@Param("id") Integer fid);
}